/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package masters.servlet.insumos;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import masters.dao.InsumosDAO;
import masters.excepcion.DAOExcepcion;
import masters.modelo.Insumos;

/**
 * Servlet implementation class for Servlet: CategoriaBuscarServlet
 *
 */
public class InsumosBuscarServlet extends javax.servlet.http.HttpServlet
        implements javax.servlet.Servlet {

    static final long serialVersionUID = 1L;

    /*
     * (non-Java-doc)
     *
     * @see javax.servlet.http.HttpServlet#HttpServlet()
     */
    public InsumosBuscarServlet() {
        super();
    }

    /*
     * (non-Java-doc)
     *
     * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
     *      HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /*
     * (non-Java-doc)
     *
     * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
     *      HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        InsumosDAO dao = new InsumosDAO();
        Collection<Insumos> tipo_tela = new ArrayList<Insumos>();
        try {
            tipo_tela = dao.buscarPorNombre(request.getParameter("nombre"));
            request.setAttribute("tipo_tela", tipo_tela);
            request.getRequestDispatcher("/admininsumos.jsp").forward(
                    request, response);
        } catch (DAOExcepcion e) {
            System.err.println("Error");
            RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
            rd.forward(request, response);
        }

    }
}
